﻿/*--------------------------------------------------------------
 * Author : Shine K Velayudhan 
 ---------------------------------------------------------------*/
using System;

namespace IQN.Logging
{
    public class ErrorMessage : LogMessage
    {

        public Exception Error { get; set; }
        internal ErrorMessage(string messageSource, MessageLevel messageLevel, Exception error)
            : base(messageSource, messageLevel)
        {
            this.Error = error;
        }
        public override string MessageText
        {
            get
            {
                return ((this.Error == null) ? "--" : this.Error.Message);
            }
        }
        public override MessageType MessageType
        {
            get
            {
                return MessageType.Error;
            }
        }
        public string RootCause
        {
            get
            {
                if (null == this.Error)
                {
                    return "--";
                }
                if (null == this.Error.InnerException)
                {
                    return this.Error.Message;
                }
                Exception error = this.Error;
                while (null != error.InnerException)
                {
                    error = error.InnerException;
                }
                return error.Message;
            }
        }
    }
}
